<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('合作设立子基金') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('主体类型')" prop="busType">
        <el-select v-model="queryParams.busType" filterable clearable :placeholder="$t('主体类型')" @change="switchBusType">
          <el-option
            v-for="dict in busTypeOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('主体名称')" prop="busId">
        <MainBodySelect v-model="queryParams.busId" :show-label="false" :parameters="queryParams.busType" :scope-authority="true" />
      </el-form-item>
      <el-form-item :label="$t('周期')" prop="yearMonth">
        <el-date-picker
          v-model="queryParams.yearMonth"
          :clearable="false"
          type="month"
          value-format="yyyy-MM"
          :placeholder="$t('周期')"
        />
      </el-form-item>
      <el-form-item :label="$t('仅筛选纯政策基金')" prop="isCzcFund">
        <dictSelect
          v-model="queryParams.isCzcFund"
          :clearable="true"
          dictionary="sys_yes_no"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="exportHandle"
        >{{ $t("导出") }}</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="cooperativeEstablishmentSubFundList" :show-summary="true" :summary-method="getSummaries" tooltip-effect="darkTable" border>
      <el-table-column :label="$t('序号')" type="index" align="center" width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金名称')" align="center" prop="fundName" show-overflow-tooltip min-width="280">
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/deal/home/dealBaseHome',query:{id: scope.row.dealId, companyId: scope.row.companyId, gpId: scope.row.gpId, dealType: 'bf'}}"
            class="link_a"
          >{{ scope.row.dealName }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金类型')" align="center" prop="organizationalForm" show-overflow-tooltip min-width="150" />
      <el-table-column :label="$t('参与方式')" align="center" prop="participationMethod" show-overflow-tooltip min-width="150" />
      <el-table-column :label="$t('发起人')" align="center" prop="promoter" show-overflow-tooltip min-width="150" />
      <el-table-column :label="$t('基金管理人')" align="center" prop="gpName" show-overflow-tooltip min-width="150" />
      <el-table-column :label="$t('GP团队核心人士')" align="center" prop="gpCoreTeamName" show-overflow-tooltip min-width="150" />
      <el-table-column :label="$t('东方国资委派人员统计')" align="center" prop="dealExpatsUserName" show-overflow-tooltip min-width="180" />
      <el-table-column :label="$t('存续期限')" align="center" prop="fundTerm" show-overflow-tooltip min-width="150" />
      <el-table-column :label="$t('基金成立日期')" align="center" prop="fundSetTime" show-overflow-tooltip min-width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fundSetTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('工商变更日期')" align="center" prop="companyChangeTime" show-overflow-tooltip min-width="150" />
      <el-table-column :label="$t('基金规模(万元)')" align="center" prop="subscribeScale" show-overflow-tooltip min-width="150">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.subscribeScale) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('所属阶段')" align="center" prop="fundStage" show-overflow-tooltip min-width="150" />
      <el-table-column :label="$t('认缴出资额(万元)')" align="center" prop="subscribeScale" show-overflow-tooltip min-width="150">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.subscribeScale) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('实缴出资额(万元)')" align="center" prop="paidInScale" show-overflow-tooltip min-width="150">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.paidInScale) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('东方国资出资主体及认缴出资额(万元)')" align="center" prop="investmentAmount" show-overflow-tooltip min-width="240">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.investmentAmount) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('东方国资实缴出资额(万元)')" align="center" prop="actualPaymentMoney" show-overflow-tooltip min-width="180">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.actualPaymentMoney) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('东方国资出资主体及占股比例')" align="center" prop="latestShareholdingRatio" show-overflow-tooltip min-width="200" />
      <el-table-column :label="$t('基金概述')" align="center" prop="dealIntroduction" show-overflow-tooltip min-width="150" />
      <el-table-column :label="$t('基金最新估值(万元)')" align="center" prop="valuationAmount" show-overflow-tooltip min-width="150">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.valuationAmount) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金退出金额(万元)')" align="center" prop="distributionAmount" show-overflow-tooltip min-width="150">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.distributionAmount) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('历经几次产权变动(变动时间、明细)')" align="center" prop="mattersItemDesc" show-overflow-tooltip min-width="240" />
      <el-table-column :label="$t('分红本金(万元)')" align="center" prop="distributionPrincipal" show-overflow-tooltip min-width="150">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.distributionPrincipal) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('分红收益(万元)')" align="center" prop="distributionIncome" show-overflow-tooltip min-width="150">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.distributionIncome) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  getCooperativeEstablishmentSubFundList,
  getCooperativeEstablishmentSubFundSum
} from '@/api/sass/dfgz/dfgzReport'
import MainBodySelect from '@/components/MainBodySelect'
export default {
  name: 'CooperativeEstablishmentSubFundView',
  components: {
    MainBodySelect
  },
  data() {
    return {
      cooperativeEstablishmentSubFundList: [],
      cooperativeEstablishmentSubFundSum: {},
      total: 0,
      loading: false,
      queryParams: {
        busType: undefined,
        busId: undefined,
        yearMonth: this.getNowFormatDate(),
        isCzcFund: 'N',
        pageNum: 1,
        pageSize: 10
      },
      busTypeOptions: [
        {
          dictValue: 'fund',
          dictLabel: '在管基金'
        },
        {
          dictValue: 'internal',
          dictLabel: '内部机构'
        }
      ]
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      getCooperativeEstablishmentSubFundList(this.queryParams).then(response => {
        getCooperativeEstablishmentSubFundSum(this.queryParams).then(res => {
          this.cooperativeEstablishmentSubFundSum = res.data
        })
        this.cooperativeEstablishmentSubFundList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    // 获取当前日期函数
    getNowFormatDate() {
      const date = new Date()
      const year = date.getFullYear() // 获取完整的年份(4位)
      let month = date.getMonth() + 1 // 获取当前月份(0-11,0代表1月)
      if (month < 10) month = `0${month}` // 如果月份是个位数，在前面补0
      // let strDate = date.getDate() // 获取当前日(1-31)
      // if (strDate < 10) strDate = `0${strDate}` // 如果日是个位数，在前面补0
      return `${year}-${month}`
    },
    exportHandle() {
      this.$confirm(this.$t('是否确认导出数据项?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(() => {
        this.downLoadExcel('/dfgz/report/getCooperativeEstablishmentSubFundList/export', this.queryParams)
      }).catch(() => {
      })
    },
    // 合计
    getSummaries(param) {
      const { columns } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
        } else if (index === 11) {
          sums[index] = this.moneyFormat(this.cooperativeEstablishmentSubFundSum.subscribeScale)
        } else if (index === 13) {
          sums[index] = this.moneyFormat(this.cooperativeEstablishmentSubFundSum.subscribeScale)
        } else if (index === 14) {
          sums[index] = this.moneyFormat(this.cooperativeEstablishmentSubFundSum.paidInScale)
        } else if (index === 15) {
          sums[index] = this.moneyFormat(this.cooperativeEstablishmentSubFundSum.investmentAmount)
        } else if (index === 16) {
          sums[index] = this.moneyFormat(this.cooperativeEstablishmentSubFundSum.actualPaymentMoney)
        } else if (index === 19) {
          sums[index] = this.moneyFormat(this.cooperativeEstablishmentSubFundSum.valuationAmount)
        } else if (index === 20) {
          sums[index] = this.moneyFormat(this.cooperativeEstablishmentSubFundSum.distributionAmount)
        } else if (index === 22) {
          sums[index] = this.moneyFormat(this.cooperativeEstablishmentSubFundSum.distributionPrincipal)
        } else if (index === 23) {
          sums[index] = this.moneyFormat(this.cooperativeEstablishmentSubFundSum.distributionIncome)
        } else {
          sums[index] = ''
        }
      })
      return sums
    },
    switchBusType() {
      this.queryParams.busId = undefined
    }
  }
}
</script>
